package com.manager.student;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * StudentValidator.
 */
public class StudentValidator extends Validator {
	
	protected void validate(Controller controller) {
		validateRequiredString("student.name", "nameMsg", "请输入名字!");
		validateRequiredString("student.age", "ageMsg", "请输入年龄!");
		validateRequiredString("student.sex", "sexMsg", "请输入性别!");
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(Student.class);
		
		String actionKey = getActionKey();
		if (actionKey.equals("/student/save"))
			controller.render("add.html");
		else if (actionKey.equals("/student/update"))
			controller.render("edit.html");
	}
}
